home *** CD-ROM | disk | FTP | other *** search
- /* ALSend.e */
-
- /* This is the program that gets all incoming messages piped through it */
-
- /*
- * Receives in a message on the standard input, parses it, and passes it on to the
- * AList server for processing.
- *
- * Will attempt to start AList if it can't find it's port.
- *
- * Note that very little would need to be done to this to make it pure.
- */
-
-
- MODULE 'other/aldef'
-
- PROC main()
- DEF x
-
- barnacle_start()
- IF (alist_replyport = NIL)
- WriteF ('Major problems, dude! I can\at even get a port open!\n')
- CleanUp (20)
- ENDIF
-
- IF (IF (arg) THEN (arg[0]) ELSE FALSE)
- arg := TrimStr (arg)
- x := StrLen (arg)-1
- WHILE (IF (x < 0) THEN FALSE ELSE (arg[x] < 33))
- DEC x
- ENDWHILE
-
- arg[x+1] := 0
- ENDIF
-
- parse_msg(arg) /* This is the list name, if specified */
-
- barnacle_end()
- ENDPROC
-
-
- /*
- * Attempts to send the message.
- */
- PROC parse_msg (list:PTR TO CHAR)
- DEF name:PTR TO CHAR, str:PTR TO CHAR, buff:PTR TO CHAR, tmp:PTR TO CHAR, flag, tmp2
-
- buff := String (256)
- IF (list)
- StrCopy (buff, list)
- list := String (EstrLen (buff))
- StrCopy (list, buff)
- buff[0] := 0
- ENDIF
- name := str := tmp := tmp2 := flag := NIL
- /* Eat the command line args */
- Fgets (stdin, buff, 256)
-
- WHILE (Fgets (stdin, buff, 256))
- /* Eat preceeding spaces */
- IF (flag = NIL)
- tmp := TrimStr (buff)
- IF (tmp[0] <> NIL) THEN flag := 1
- ENDIF
- tmp := NIL
-
- IF (flag)
- SetStr (buff, StrLen (buff))
- tmp := String (StrLen (buff))
- StrCopy (tmp, buff)
- IF (TrimStr (tmp) = (tmp + EstrLen (tmp))) THEN flag := 2
- IF (flag = 1)
- IF (StrCmp (tmp, 'To: ', 4))
- list := get_addr (list, tmp + 4)
- DisposeLink (tmp)
- IF (list)
- tmp := InStr (list, '@')
- IF (tmp > -1)
- /* Strip off the end stuff */
- list[tmp] := 0
- SetStr (list, tmp)
- ELSE
- tmp := EstrLen (list)
- WHILE (IF (tmp > -1) THEN (list[tmp] <> "!") ELSE FALSE)
- DEC tmp
- ENDWHILE
- IF (tmp > -1)
- /* Found one... Fix this UUCP address... */
- StrCopy (buff, list+tmp+1)
- DisposeLink (list)
- list := String (EstrLen (buff))
- StrCopy (list, buff)
- ENDIF
- ENDIF
- ENDIF
- tmp := NIL
- ELSEIF (StrCmp (tmp, 'From: ', 6))
- name := get_addr (name, tmp + 6)
- ENDIF
- ENDIF
-
- IF (tmp)
- IF (str = NIL)
- str := tmp
- tmp2 := tmp
- ELSE
- Link (tmp2, tmp)
- tmp2 := tmp
- ENDIF
- ENDIF
- ENDIF
- ENDWHILE
-
- DisposeLink (buff)
-
- IF (str)
- flag := put_msg (ALM_SEND, str, list, name)
- DisposeLink (str) /* Yup, this frees each link in the chain */
- IF (flag) THEN WriteF ('failed ')
- ENDIF
-
- IF (list) THEN DisposeLink (list)
- IF (name) THEN DisposeLink (name)
- ENDPROC
-
-
- PROC get_addr (tmp1, str:PTR TO CHAR)
- DEF msg:PTR TO almsg
-
- IF (put_msg (ALM_ADDR, str))
- WriteF ('Aborting send!\n')
- RETURN
- ENDIF
-
- /* Protocol says we gotta wait for a response from ALM_ADDR */
- msg := WaitPort (alist_replyport)
-
- IF (StrLen (msg.field2))
- IF (tmp1) THEN DisposeLink (tmp1)
- tmp1 := String (StrLen (msg.field2))
- StrCopy (tmp1, msg.field2)
- ENDIF
-
- /* Make sure we thank the good program... */
- Remove (msg)
- ReplyMsg (msg)
- ENDPROC tmp1
-
-
- /*
- * Returns TRUE if it didn't happen.
- */
- PROC put_msg (cmd, arg, f1=NIL, f2=NIL)
- DEF x
-
- IF (barnacle_put_msg (NIL, cmd, arg, f1, f2))
- IF (Execute ('run AList >NIL:', NIL, stdout) = NIL)
- WriteF ('Can\at find AList!\n')
- RETURN TRUE
- ENDIF
- IF (Execute ('waitforport AList', NIL, stdout) = NIL)
- WriteF ('Can\at find the WaitForPort command!\n')
- RETURN TRUE
- ELSE /* Wait long enough for it */
- Execute ('waitforport AList', NIL, stdout)
- Execute ('waitforport AList', NIL, stdout)
- ENDIF
- RETURN barnacle_put_msg (NIL, cmd, arg, f1, f2)
- ENDIF
- ENDPROC FALSE
-
-
-